package com.myzl.web.controller.visualization;

import com.myzl.coal.service.IDemoService;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.enums.DemoEnum;
import com.myzl.web.controller.coal.request.DemoSetRequest;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

/**
 * @ClassName VisualizationControl
 * @Author wzb
 * @Date 2023/6/7 15:02
 * @Description
 */
@RestController
@Slf4j
@Data
@RequestMapping("/visualization/demo/")
public class DemoController {
    private final IDemoService demoService;


    @GetMapping("/allSwitch")
    public AjaxResult allSwitch() {
        Map<String, Boolean> allSwitch = demoService.getAllSwitch();
        return AjaxResult.success(allSwitch);
    }

    @PostMapping("/setData")
    public AjaxResult setData(@RequestBody DemoSetRequest request                              ) {
        if (Objects.nonNull(request.getPlat())) {
            demoService.setRedisPoliceFlag(DemoEnum.plat,request.getPlat());
        }
        if (Objects.nonNull(request.getCoalLow())) {
            demoService.setRedisPoliceFlag(DemoEnum.coalLow,request.getCoalLow());
        }
        if (Objects.nonNull(request.getCoalHigh())) {
            demoService.setRedisPoliceFlag(DemoEnum.coalHigh,request.getCoalHigh());
        }
        if (Objects.nonNull(request.getCoalDistribution())) {
            demoService.setRedisPoliceFlag(DemoEnum.coalDistribution,request.getCoalDistribution());
        }
        if (Objects.nonNull(request.getEfficiency())) {
            demoService.setRedisPoliceFlag(DemoEnum.efficiency,request.getEfficiency());
        }
        if (Objects.nonNull(request.getMotor_temperature())) {
            demoService.setRedisPoliceFlag(DemoEnum.motor_temperature,request.getMotor_temperature());
        }
        if (Objects.nonNull(request.getExciter_temperature())) {
            demoService.setRedisPoliceFlag(DemoEnum.exciter_temperature, request.getExciter_temperature());
        }

        return AjaxResult.success();
    }

}
